<template>

  <a-drawer
    :title="title"
    width="50%"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @close="handleCancel"
    cancelText="关闭"
    style="height: 100%;overflow: auto;padding-bottom: 53px;">

    <a-spin :spinning="confirmLoading">

      <a-form :form="form">

        <template>
        <a-form-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <cn-dict-select-tag :options="{value:'dictDataCode',label:'dictDataDesc'}" :triggerChange="true"
                             dictCode="bpm_statuster"
                             v-decorator="['bpmStatus',validatorRules.bpmStatus]" placeholder="请选择审核状态"/>
        </a-form-item>
        </template>

        <template>
          <a-form-item
            :labelCol="labelCol"
            :wrapperCol="wrapperCol"
            label="审核意见">
            <a-textarea placeholder="请输入审核意见" v-decorator="['auditOpinion',{} ]"/>
          </a-form-item>
        </template>
      </a-form>


    </a-spin>
    <div class="drawer-bootom-button" v-show="!disableSubmit">
      <a-popconfirm title="确定放弃审核？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleOk" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>

</template>

<script>
  import {httpAction} from '@/api/manage'
  import pick from 'lodash.pick'
  import AFormItem from 'ant-design-vue/es/form/FormItem'
  import ATextarea from 'ant-design-vue/es/input/TextArea'
  import JImageUpload from '@/components/cn-form/JImageUpload'
  import JTreeSelect from '@/components/cn-form/JTreeSelect'
  import JSelectUserByDep from '@/components/cn-select-popup/JSelectUserByDep'
  import JSelectTerminal from '@/components/cn-select-popup/JSelectTerminal'

  export default {
    name: 'TerminalCerModal',
    components: {
      JImageUpload,
      AFormItem,
      ATextarea,
      JTreeSelect,
      JSelectUserByDep,
      JSelectTerminal
    },
    data() {
      return {
        title: "审核",
        visible: false,
        selecttype: '',
        model: {},
        toggleSearchStatus: false,
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        disableSubmit:false,
        form: this.$form.createForm(this),

        validatorRules: {
          bpmStatus: {
            rules: [{
              required: true, message: '', trigger: 'submit'
            }]
          },
          auditOpinion: {
            rules: [{
              required: true, message: '', trigger: 'submit'
            }]
          }
        },
        url: {
          edit: window._CONFIG['domianURL'] + "/terminal/cnCertificateDetailController/updateEntity",
        },
      }
    },
    methods: {
      dotype(val) {
        this.selecttype = val
      },
      add() {
        this.edit({});
      },
      edit(record) {
        this.form.resetFields();
        this.model = Object.assign({}, {id:record});
        this.visible = true
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let formData = Object.assign(this.model, values);
            //时间格式化
            httpAction(this.url.edit, formData, 'post').then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel() {
        this.close()
      },
    }
  }
</script>

<style scoped>
  .drawer-bootom-button {
    position: absolute;
    bottom: -8px;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: right;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }
</style>